<?php app::import('model', 'Presentacionesmedicamento') ?>
<?php $presentacion = new Presentacionesmedicamento() ?>
<?php app::import('model', 'Medidasmedicamento')?>
<?php $medida = new Medidasmedicamento();?>
<?php echo $this->Html->script(array('print')); ?>
<?php if (!empty($datosMedicamentosPaciente)): ?>
                    <div id="areaImprimir">
                        <table class="wtbl_list">
                            <thead>
                                <tr>
                                    <th>Medicamento</th>
                                    <th>P/u</th>
                                    <th>Seguro</th>
                                    <th>Cantidad</th>                                    
                                    <th style="width: 100px">Administracion</th>
                                    <th>Observaciones</th>
                                    <th>Acciones</th>
                                </tr>
                            </thead>
                            <tbody>                   
                                <?php $i = 0; ?>
                                <?php foreach ($datosMedicamentosPaciente as $dmp): ?>

                                    <tr class="<?php echo $estilo = fmod($i, 2) ? "tr_even" : "tr_odd"; ?>">
                                        <?php if(empty($dmp['MedicamentosPaciente']['medicamento'])):?>
                                        <?php $pm = $presentacion->find('first', array('conditions'=>array('Presentacionesmedicamento.id'=>$dmp['Medicamento']['presentacionesmedicamento_id'])))?>
                                        <?php $med = $medida->find('first', array('conditions'=>array('Medidasmedicamento.id'=>$dmp['Medicamento']['medidasmedicamento_id'])))?>
                                        <td><?php echo $dmp['Medicamento']['nombre']; ?>&nbsp;de <?php echo $dmp['Medicamento']['porporcion']?>&nbsp;<?php echo $med['Medidasmedicamento']['sigla']?>&nbsp;en&nbsp;<?php echo $pm['Presentacionesmedicamento']['nombre']?></td>
                                        <?php else:?>
                                        <td><?php echo $dmp['MedicamentosPaciente']['medicamento']?></td>
                                        <?php endif;?>
                                        <td><?php echo $dmp['MedicamentosPaciente']['precio']; ?></td>
                                        <td><?php echo $dmp['MedicamentosPaciente']['seguro']; ?></td>
                                        <td><?php echo $dmp['MedicamentosPaciente']['cantidad']; ?></td>
                                        <td><?php echo $dmp['MedicamentosPaciente']['dosis']; ?></td>
                                        <td><?php echo $dmp['MedicamentosPaciente']['observaciones']; ?></td>
                                        <td>
                                            <?php echo $this->Html->link($this->Html->image("iconos/elim.png", array("alt" => 'delete', 'title' => 'ELIMINAR RECETA')), array('controller'=>'Recetaspacientes','action' => 'eliminareceta',  $dmp['MedicamentosPaciente']['id'],$dmp['MedicamentosPaciente']['consultasexterna_id'], $dmp['Medicamento']['nombre']), array('escape' => false), 'esta seguro de eliminar ' . $dmp['MedicamentosPaciente']['nombre']); ?>
                                        </td>         
                                    </tr>	
                                    <?php $i++; ?>
                                <?php endforeach; ?>
                                    <?php if(!empty($recomendaciones)):?>
                                    <tr>
                                        <th>
                                            Recomendaciones
                                        </th>
                                        <td colspan="4">
                                            <?php echo $recomendaciones['Consultasexterna']['recomendaciones']?>
                                        </td>
                                    </tr>
                                    <?php endif;?>
                            </tbody>
                        </table>
                    </div>
                    <div class="btn_30_orange"> 
                        <a href="<?php echo $this->Html->url(array('controller' => 'Recetaspacientes', 'action' => 'imprimir', $idConsulta)); ?>">
                            <span class="icon find_co"></span><span class="btn_link">Vista Previa de Impresion</span>
                        </a>
                    </div>
                <?php endif; ?>
<script>
        $(document).ready(function() {
            $("#vertical").hide();

        $("#btnVertical").click(function() {
            $("#vertical").toggle('slow');
        });
        $("#btnImprimir").click(function() {
            console.log('<?php echo $this->webroot ?>');
            //printElem({leaveOpen: true, printMode: 'popup'});
            printElem({overrideElementCSS: ["<?php echo $this->webroot ?>/css/imprimetabla.css"]});
        });

    });
    function printElem(options) {
        $('#areaImprimir').printElement(options);
    }
</script>